package com.example.jasonrpc.server.byRegistry;

import com.example.jasonrpc.codec.Decoder;
import com.example.jasonrpc.codec.Encoder;
import com.example.jasonrpc.codec.JSONDecoder;
import com.example.jasonrpc.codec.JSONEncoder;
import com.example.jasonrpc.registry.RegistryCenter;
import com.example.jasonrpc.transport.HttpTransportServer;
import com.example.jasonrpc.transport.TransportServer;

import java.util.Objects;

public class RpcServerConfigByRegistry {
    private Class<? extends TransportServer> transportClass;
    private Class<? extends Encoder> encoderClass;
    private Class<? extends Decoder> decoderClass;
    private RegistryCenter center;
    private int port;

    public RpcServerConfigByRegistry(RegistryCenter center, int servicePort) {
        transportClass = HttpTransportServer.class;
        encoderClass = JSONEncoder.class;
        decoderClass = JSONDecoder.class;
        this.center = center;
        this.port = servicePort;
    }

    @Override
    public String toString() {
        return "RpcServerConfig{" +
                "transportClass=" + transportClass +
                ", encoderClass=" + encoderClass +
                ", decoderClass=" + decoderClass +
                ", port=" + port +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        RpcServerConfigByRegistry that = (RpcServerConfigByRegistry) o;
        return port == that.port && transportClass.equals(that.transportClass) && encoderClass.equals(that.encoderClass) && decoderClass.equals(that.decoderClass) && center.equals(that.center);
    }

    @Override
    public int hashCode() {
        return Objects.hash(transportClass, encoderClass, decoderClass, center, port);
    }

    public Class<? extends TransportServer> getTransportClass() {
        return transportClass;
    }

    public void setTransportClass(Class<? extends TransportServer> transportClass) {
        this.transportClass = transportClass;
    }

    public Class<? extends Encoder> getEncoderClass() {
        return encoderClass;
    }

    public void setEncoderClass(Class<? extends Encoder> encoderClass) {
        this.encoderClass = encoderClass;
    }

    public Class<? extends Decoder> getDecoderClass() {
        return decoderClass;
    }

    public void setDecoderClass(Class<? extends Decoder> decoderClass) {
        this.decoderClass = decoderClass;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public RegistryCenter getCenter() {
        return center;
    }

    public void setCenter(RegistryCenter center) {
        this.center = center;
    }
}
